package com.station.service.mapper;

import com.station.annotation.DataSource;
import com.station.vo.ItemVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description:
 * @Author: dongfangyu
 * @Date: 2025/9/23
 */
@Mapper
public interface ItemMapper {


    /**
     * 查询商品列表
     * @param vendorId
     * @return
     */
    @DataSource("base")
    @Select("SELECT i.id AS itemId, " +
            "i.itemName, " +
            "i.barcode, " +
            "i.unit, " +
            "vc.catCode, " +
            "vc.parentCode FROM " +
            "item i " +
            "INNER JOIN vendorcategory vc ON vc.catCode = i.icatCode " +
            "AND vc.vendorId = i.vendorId " +
            "WHERE " +
            "i.df = 0 " +
            "AND i.vendorId = #{vendorId} " +
            "AND i.itemStatus NOT IN (1,2,3)")
    List<ItemVo> queryItemList(Long vendorId);

    /**
     * 根据商品编码查询商品信息
     * @param vendorId
     * @param skuCode
     * @return
     */
    @DataSource("base")
    @Select("SELECT i.id AS itemId, "  +
            "i.itemName, "  +
            "i.barcode, "  +
            "i.unit, "  +
            "i.itemType, "  +
            "vc.catCode, "  +
            "vc.parentCode FROM "  +
            "item i "  +
            "INNER JOIN vendorcategory vc ON vc.catCode = i.icatCode "  +
            "AND vc.vendorId = i.vendorId "  +
            "WHERE "  +
            "i.df = 0 "  +
            "AND i.vendorId = #{vendorId} "  +
            "AND i.itemCode = #{skuCode} " +
            "limit 1 ")
    ItemVo queryItemBySkuCode(@Param("vendorId") Long vendorId, @Param("skuCode") String skuCode);
}
